// 1. 字面量类型的基本使用
const name:'张三' = '张三'

// 2. 将多个字面量类型联合起来
type Direction = "left" | "right" | "up" | "down"
const dl: Direction = "left"
const dr: Direction = "right"
const dt: Direction = "top" // 报错

// 举例：封装请求
type MethodType = "get" | "post"
function request(url: string, method: MethodType) {

}
request("http://api.com","post")

// TS细节 
const info = {
  url: 'xxxx',
  method: "post"
}
request(info.url, info.method) // 报错，这里获取到info.method类型为string而不是post

// 解决方案1： 类型断言
request(info.url, info.method as "post") 

// 解决方案2： 直接让info对象是一个字面量类型
const info1 = {
  url: 'xxxx',
  method: "post"
} as const
request(info1.url, info1.method)

export {}